//
//  TSWalletRecordViewController.swift
//  TSProfitProject
//
//  Created by TMS on 2019/11/8.
//  Copyright © 2019 TMS. All rights reserved.
//

import UIKit

class TSWalletRecordViewController: TSBaseViewController {

    var walletTitle : String!
    var tableController : TSBaseTableViewController!
    var dataSource : [TSWalletRecordModel] = []
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        configViews()
        setupNavigationTitle(title: walletTitle)
    }

}

extension TSWalletRecordViewController : UITableViewDelegate {
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        62
    }
    
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        let header = UIView.init(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: 0.001))
        header.backgroundColor = WHITE_COLOR
        return header
    }
    
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        0.001
    }
    
    func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
        
        let footer = UIView.init(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: 0.001))
        footer.backgroundColor = WHITE_COLOR
        return footer
    }
    
    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        0.001
    }
}

extension TSWalletRecordViewController : UITableViewDataSource {
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        dataSource.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

        var cell = tableView.dequeueReusableCell(withIdentifier: NSStringFromClass(TSWalletRecordTableViewCell.self)) as? TSWalletRecordTableViewCell
        
        if cell == nil {
            cell = TSWalletRecordTableViewCell.init(style: .default, reuseIdentifier: NSStringFromClass(TSWalletRecordTableViewCell.self))
        }
        
        let last = indexPath.row == dataSource.count - 1
        cell?.setupCell(model: dataSource[indexPath.row], last: last)
        
        return cell!
    }
}

extension TSWalletRecordViewController {
    
    func configViews() {
        
        tableController = TSBaseTableViewController(style: .grouped)
        tableController.emptyAlertText = "暂无记录"
        tableController.tableView.backgroundColor = WHITE_COLOR
        tableController.tableView.delegate = self;
        tableController.tableView.dataSource = self
        tableController.tableView.separatorStyle = .none
        self.view.addSubview(tableController.tableView)
        tableController.tableView.snp.makeConstraints { (make) in
            make.left.right.bottom.equalToSuperview()
            make.top.equalTo(T_NAVBARHEIGHT)
        }
    }
}
